﻿
#include <iostream>
#include "windows.h"
#include "../../win_com/xx_inline_hook.hpp"
#include "../../win_com/xx_mem.hpp"


char trampoline[1024];
typedef int (WINAPI* MessageBox_t)(HWND, LPCSTR, LPCSTR, UINT);
MessageBox_t ori_func = nullptr;

int
WINAPI
My_MessageBoxA(
    _In_opt_ HWND hWnd,
    _In_opt_ LPCSTR lpText,
    _In_opt_ LPCSTR lpCaption,
    _In_ UINT uType) {
    
    lpText = "world";
    lpCaption = "hello";
    ori_func = (MessageBox_t)((char*)trampoline);
    ori_func(hWnd,lpText,lpCaption,uType);
    return 0;
}

int main()
{
    int64_t offset = xx_get_offset(&MessageBoxA, &My_MessageBoxA);
    bool need_far_jmp = xx_int32_overflow(offset);
    printf("need_far_jmp=%u \n", need_far_jmp);
    
    xx_mem_unprotect(trampoline, 1024);
    xx_make_trampoline(trampoline, &MessageBoxA, 14);
    xx_reloc_offset(&MessageBoxA, trampoline, 4+3+3);

    xx_mem_unprotect(&MessageBoxA, 1024);
    xx_setjmp(&MessageBoxA, &My_MessageBoxA);

    ::MessageBoxA(0, "发现非法软件", "警告",  0);
}


